import { pageProjects, listUser, saveProject,getProjectDetail,getProjectBrief ,updateProject,saveUser,deleteUser} from '@/services/project/project';



const Model = {
  namespace: 'project',

  state: {
    projectData: [],
    members: [],
    isUserLoading:false
  },
  effects: {
    *page({ payload }, { call, put }) {
      const response = yield call(pageProjects, payload);
      yield put({
        type: 'setProjects',
        payload: response.data,
      });
    },

    *getProjectDetail({ payload }, { call, put }) {
      const response = yield call(getProjectDetail, payload);
      yield put({
        type: 'setProjectDetail',
        payload: response.data,
      });
    },
    
    *getProjectBrief({ payload }, { call, put }) {
      const response = yield call(getProjectBrief, payload);
      yield put({
        type: 'setProjectBrief',
        payload: response.data,
      });
    },

    *listUser({ payload }, { call, put }) {
      const response = yield call(listUser,payload.projectId, payload.params);
      if(response && response.success) {
        yield put({
          type: 'setUser',
          payload: response.data,
        });
      }
    },
      
  },
  reducers: {
    setProjects(state, action) {
      return { ...state, projectData: action.payload };
    },

    setProjectDetail(state, action){
      return { ...state, projectDetail: action.payload };
    },

    setProjectBrief(state, action){
      return { ...state, projectBrief: action.payload };
    },

    setUser(state, action) {
      return { ...state, userPage: action.payload };
    },
  },
};
export default Model;
